// url: https://leetcode.cn/problems/majority-element/description/?envType=study-plan-v2&envId=top-interview-150
package interview_classic.array_or_str;
public class Solution169 {
    public int majorityElement(int[] nums) {
        int count = 1;
        int curNum = nums[0];
        for (int i = 1; i < nums.length; i++) {
            if (curNum == nums[i]) {
                count++;
            } else {
                if (count == 0) {
                    curNum = nums[i];
                    count++;
                } else {
                    count--;
                }
            }
        }
        return curNum;
    }
}
